<?php 
include("header.inc");
// Requesting URL data
$progid = $_GET["progid"];
$page   = $_GET["page"];
if(empty($progid) or !intval($progid)) { // If progid is not specified or contains wrong data
	header("Location: /"); // Redirecting to the main page
	exit;
}
// Connecting to database
if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
	die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
}
mysql_select_db($dbname);

// Receiving the required information from paddata
$result = mysql_query("SELECT * FROM paddata WHERE progid='$progid'", $link_id);
$query = mysql_fetch_array($result);
mysql_free_result($result);
if(empty($query)) { // If there was no such entry in database
	header("HTTP/1.0 404 Not Found"); // Redirecting to the main page
	die("<p><b>No such entry in database!</b></p>\n");
}
$title        = htmlspecialchars($query["title"]);
$version      = $query["version"];
$category     = $query["category"];
$keywords     = str_replace(",",", ",htmlspecialchars($query["keywords"]));

// Establishing the displaying of software title with version
$fulltitle = $title . " " . $version;
?>
<link rel="stylesheet" type="text/css" href="<?php echo $cssfile; ?>">
<table bgcolor="White" width="980" align="center">
<tr><td width="180" valign="top">
<table width=180 border=0 cellpadding=0 cellspacing=0 background="images/middle.gif">
          <tbody>
            <tr>
              <td height="2" class="table-top"></td>
            </tr>
            <tr>
              <td align=left valign=top class="left">
<?php
$which_class = "";
include_once('categories1.inc');
?>
</td>
            </tr>
            <tr>
              <td height="8" class="table-bottom"></td>
            </tr>
          </tbody>
        </table>
      <br>
        <table width=180 
            border=0 align="center" cellpadding=0 cellspacing=0 
            background="images/middle.gif">
          <tbody>
            <tr>
              <td width="8" height="2" class="table-top"></td>
              <td width="172" class="table-top"></td>
            </tr>
            <tr>
              <td align=left valign=center class="left-rss">:<br>
                  <br>
                  <p></p>
                <p></p></td>
              <td align=left valign=center class="left-rss"><span class="left-b"><img src="images/rss.gif" width="36" height="14">RSS Feeds</span><br>
                <img src="images/rss-1.gif" alt="new" width="14" height="14"><a href="rss.php">New Releases and Updates</a><br>
                  <img src="images/rss-1.gif" alt="new" width="14" height="14"><a href="rss.php?feed=popular">Most Popular Software</a><br>
                  <img src="images/rss-1.gif" alt="new" width="14" height="14"><a href="rss.php?feed=rating">Top Rated Software</a></td>
            </tr>
            <tr>
              <td height="8" colspan="2" class="table-bottom"></td>
            </tr>
          </tbody>
        </table>
&nbsp;</td>
<td valign="top">
<?php
$ppp = 15; // no of posts per page

if((empty($page)) or($page < 1)) $page = 1;
function navbar() {
	global $tcount, $firstpage, $prevpage, $page, $tpage, $nextpage, $lastpage;
	echo "<table align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n";
	echo "<tr>\n<td>\n";
	echo "<p><b>Posted reviews:</b> " . $tcount . "</p>\n";
	echo "</td>\n<td align=\"right\">\n";
	if($firstpage) {
		echo "<a class=\"umenu\" href=\"" . $firstpage . "\">First</a> &nbsp; <a class=\"umenu\" href=\"" . $prevpage . "\">Previous</a>\n";
	}
	else {
		echo "First &nbsp; Previous";
	}
	echo " &nbsp; ";
	if($tcount > 0) {
		echo "<b>Page " . $page . " of " . $tpage . "</b>\n";
	}
	echo " &nbsp; \n";
	if($nextpage) {
		echo "<a class=\"umenu\" href=\"" . $nextpage . "\">Next</a> &nbsp; <a class=\"umenu\" href=\"" . $lastpage . "\">Last</a>\n";
	}
	else {
		echo "Next &nbsp; Last\n";
	}
	echo "</td>\n</tr>\n</table><br>\n";
}

// Establishing the displaying of category and subcategory links
$xcat  = rawurlencode($category);
$cdisp = explode("::", str_replace(" & "," &amp; ",$category));
$cmach = explode("%3A%3A", $xcat);

echo "<table align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n";
echo "<tr>\n<td>\n";
echo "<p><b><a href=\"/\">C:</a></b> \\ <b><a href=\"list.php?cat=" . $cmach[0] . "\">" . $cdisp[0] ."</a></b> \\ <b><a href=\"list.php?cat=" . $xcat . "\">" . $cdisp[1] ."</a></b> \\ <b><a href=\"details.php?progid=" . $progid . "\">" . $fulltitle ."</a></b> \\ <b>Reviews</b></p>\n";
echo "</td>\n<td align=\"right\">\n";
echo "<p><a class=\"umenu\" href=\"revpost.php?progid=" . $progid . "\">Write review</a></p>\n";
echo "</td>\n</tr>\n</table><br>\n";

// Receiving users rating from usrreviews
$tcount = 0;
$result = mysql_query("SELECT * FROM usrreviews WHERE progid='$progid' ORDER BY revid DESC", $link_id);
if($result) $tcount = mysql_num_rows($result);

$tpage = intval(($tcount+$ppp-1)/$ppp);

$reload = $PHP_SELF . "?progid=" . $progid;
if($page > 1) {
	$firstpage = $reload . "&page=1";
	$prevpage = $reload . "&page=" .($page-1);
}

if($page < $tpage) {
	$nextpage = $reload . "&page=" .($page+1);
	$lastpage = $reload . "&page=" . $tpage;
}

navbar();

$count = 0;
$i = ($page-1)*$ppp;
while(($count<$ppp) && ($i<$tcount)) {
	mysql_data_seek($result,$i);
	$query = mysql_fetch_array($result);
	
	// Receiving data from database
	$revid        = $query["revid"];
	$useripaddr   = $query["useripaddr"];
	$revtime      = $query["revtime"];
	$username     = htmlspecialchars($query["username"]);
	$userrating   = $query["userrating"];
	$usercomment  = nl2br(htmlspecialchars($query["usercomment"]));
	
	// Establishing the displaying of users rating
	$userratingdisp = "<img src=\"images/u0.gif\" width=\"85\" height=\"10\" align=\"right\" alt=\"not rated\">";
	if($userrating == "1") {
		$userratingdisp = "<img src=\"images/u1.gif\" width=\"85\" height=\"10\" align=\"right\" alt=\"rating: 1\">";
	}
	if($userrating == "2") {
		$userratingdisp = "<img src=\"images/u2.gif\" width=\"85\" height=\"10\" align=\"right\" alt=\"rating: 2\">";
	}
	if($userrating == "3") {
		$userratingdisp = "<img src=\"images/u3.gif\" width=\"85\" height=\"10\" align=\"right\" alt=\"rating: 3\">";
	}
	if($userrating == "4") {
		$userratingdisp = "<img src=\"images/u4.gif\" width=\"85\" height=\"10\" align=\"right\" alt=\"rating: 4\">";
	}
	if($userrating == "5") {
		$userratingdisp = "<img src=\"images/u5.gif\" width=\"85\" height=\"10\" align=\"right\" alt=\"rating: 5\">";
	}

	echo "<table class=\"tvisible\" align=\"center\" width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n";
	echo "<tr><td class=\"tablehead\"><p>" . $userratingdisp . "<b>" . $username . "</b> (IP: " . $useripaddr . "), on " . strftime("%b %d, %Y",strtotime($revtime)) . "</p></td>\n";
	echo "<tr><td><p>" . $usercomment . "</p>\n";
	echo "</td></tr>\n";
	echo "</table><br>\n";

	$i++;
	$count++;
}
// Disconnecting from database
mysql_close($link_id);

if($tcount > 0) {
	navbar();
}
?>
<br>

</td><td class="tbody" width="182">
<table class="tvisible" align="center" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>

</tr>
</table><br>


</td></tr></table>
<?php
include_once('fooder.inc');
?>